export function parseMarkdownJSON(markdown: string): Record<string, any>[] {
    // Regular expression to match JSON objects within triple backticks
    const jsonRegex = /```json\n([\s\S]*?)```/g;

    // Extract all JSON objects from the markdown
    const jsonObjects: Record<string, any>[] = [];
    let match;
    while ((match = jsonRegex.exec(markdown)) !== null) {
        try {
            const jsonObject = JSON.parse(match[1]);
            jsonObjects.push(jsonObject);
        } catch (e) {
            console.error("Error parsing JSON object:", e);
        }
    }

    if (jsonObjects.length === 0) {
        try {
            const jsonContent = markdown.match(/{[\s\S]*}/)?.[0] || '';
            let singleJSON = JSON.parse(jsonContent);
            jsonObjects.push(singleJSON);
        } catch (e) {
            console.error("Error parsing JSON object:", e);
        }
    }

    return jsonObjects;
}
